<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>会员关系图</title>

	
	
	
	 <!-- Bootstrap Core CSS -->
	<link href="__PUBLIC__/Theme2/css/bootstrap.min.css" rel='stylesheet' type='text/css' />
	<!-- Custom CSS -->
	<link href="__PUBLIC__/Theme2/css/style.css" rel='stylesheet' type='text/css' />
	<link href="__PUBLIC__/Theme2/css/font-awesome.css" rel="stylesheet"> 
	<!-- jQuery -->
	<script src="__PUBLIC__/Theme2/js/jquery.min.js"></script>

	<link href="__PUBLIC__/Theme2/css/custom.css" rel="stylesheet">
	<!-- Metis Menu Plugin JavaScript -->
	<script src="__PUBLIC__/Theme2/js/metisMenu.min.js"></script>
	<script src="__PUBLIC__/Theme2/js/custom.js"></script>
	<!-- Graph JavaScript -->
	<script src="__PUBLIC__/Theme2/js/d3.v3.js"></script>
	<script src="__PUBLIC__/Theme2/js/rickshaw.js"></script>
	<!-- Bootstrap Core JavaScript -->
	<script src="__PUBLIC__/Theme2/js/bootstrap.min.js"></script>

	
</head>

<body>

        <div class="col-md-12 graphs">
	   <div class="xs">
  	 <h3>会员关系图 </h3>
	 
	 
    <div class="panel panel-warning" data-widget="{&quot;draggable&quot;: &quot;false&quot;}" data-widget-static="">
				
				
				
				<style>
					.table-striped td{text-align:center;font-weight:bold;}
					
					.table td, .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th{    padding: 15px 2px !important;}
					
				</style>
				<div class="panel-body no-padding">
					<table class="table table-striped"  cellpadding=0 cellspacing=0 >
						<tbody>
						
						<?php
						
							$systemName=M("system");
							$rs_systemName=$systemName->field("fenshijian")->where("sId=1")->find();
							$guoqi = $rs_systemName['fenshijian']*60*60;
						
							foreach($ceng_lists as $k=>$vitem)
							{
								$str = "<tr>";
								if($cur_level==3){
									$tmodel = M("teamname");
									if($teamCountInfo = $tmodel->where("id={$vitem[tname]} and teamCount=27")->find()){
									
										if(($teamCountInfo['addtime']+$guoqi)>time()){
											$fenstr = "<a href='__APP__/User/tiaozheng/searchname/{$vitem[name]}' color='red'>可拆分</a>";
										}
									}
									unset($tmodel);
								}
								$str .= "<td  colspan=3>{$vitem[name]}({$vitem[leveldesc]})$fenstr</td>";
								$str .= "</tr>";
								echo $str;
								echo opfunction($vitem,$cur_level);
								
								
							}
							
							function opfunction($item,$cur_level){
								$str .= shuchutop($item,$cur_level);
								if($item['level']>=4)
								{
									
									foreach($item['children'] as $c=>$cv)
									{
										if($cv['level']==3)
											$str_3 .= opfunction($cv,$cur_level);
										else
											$str .= opfunction($cv,$cur_level);
									}
								}
								if($cv['level']==3)
								{
									$str .= "<tr><td colspan=3><table style='width:100%'>";
									$str .= $str_3;
									$str .= "</tr></td></table>";
								}
								
								
								return $str;
							}
							
							
							
							function shuchutop($item,$cur_level){
							
								//echo $item['name']."__".$item['level'].'__'.$item['leveldesc'].'__<br/>';
								if($item['level']==3)
								{
									foreach($item['children'] as $c=>$cv)
									{
										if($cur_level==3){
											$str .=  shuchu($cv);
										}
										
									}
								}
								else if($item['level']==4){
									//该有虚位
									$str = "<tr><td colspan='3'><table width=100%>";
									
									foreach($item['children'] as $c=>$cv)
									{
										$users = M("users");
										$teamCount = $users->where("tname={$cv[tname]} and standardlevel={$cv[level]} ")->count();
										$teamCount_array = $users->field("id,loginname,dianlevel")->where("tname={$cv[tname]} and dianlevel={$cv[level]} and standardlevel=0")->select();
										
										$teamCount_dian = count($teamCount_array);
										
										$tmodel = M("teamname");
										if($teamCountInfo = $tmodel->where("id={$cv[tname]} and teamCount=27")->find()){
										
											$systemName=M("system");
											$rs_systemName=$systemName->field("fenshijian")->where("sId=1")->find();
											$guoqi = $rs_systemName['fenshijian']*60*60;
											
											if(($teamCountInfo['addtime']+$guoqi)>time()){
												$fenstr = "<a href='__APP__/User/tiaozheng/searchname/{$cv[name]}' color='red'>可拆分</a>";
											}
										}
										unset($tmodel);
										
										$str .= "<td>{$cv[name]}({$cv[leveldesc]})$fenstr</td>";
										unset($fenstr);
									}
									
									$str .= "</tr></td></table>";
									
									
									
								}
								else if($item['level']==5){
									//该有虚位
									$str = "<tr>";
									
									foreach($item['children'] as $c=>$cv)
									{
										if($cv['children']==1)
										{
											$str .= "<td>i+++{$cv[tname]}</td>";
										}
										$str .= "<td>{$cv[name]}({$cv[leveldesc]})</td>";
										if($cv['children']==1)
										{
											$str .= "<td>i+++{$cv[tname]}</td>";
										}
									}
									
									$str .= "</tr>";
									
									
									
								}
								else if($item['level']==2){
									
									//该有虚位
									$str = "<tr>";
									
									foreach($item['children'] as $c=>$v)
									{
										$str .= shuchu01($v);
										
									}
									
									$str .= "</tr>";
								}
								else if($item['level']==1){
									$str = "<tr>";
									
									foreach($item['children'] as $c=>$cv)
									{
										$str .= "<td>{$cv[name]}({$cv[leveldesc]})</td>";
										
									}
									
									$str .= "</tr>";
								}
								
								return $str;
							}
		
							function shuchu($item){

								if($item['level']==2)
								{
									$i=0;
									$str = "<td><table width=100% cellpadding=0 cellspacing=0><tr><td colspan=3>{$item[name]}({$item[leveldesc]})</td></tr><tr>";
									foreach($item['children'] as $k=>$v){
										
										$str .= shuchu01($v);
									}	
									$str .= "</tr>";
									
									$str .= "</table></td>";
								}
								
								return $str;
							}
							
							function shuchu01($v)
							{
								$str .= "<td style='padding:15px 0 !important'><table width=100% cellpadding=0 cellspacing=0><tr><td style='    border-bottom: 1px solid red;'>{$v[name]}</td></tr>";
								foreach($v['children'] as $c=>$cv)
								{
									$str .= "<tr><td>{$cv[name]}</td></tr>";// 3
									
								}
								
								if(3-$v['childrencount']>0)
								{
									$i=0;
								
									for($i=$v['childrencount'];$i<3;$i++)
									{
										$str .= "<tr><td>i++{$i}</td></tr>";
									}
								}
								
								
								$str .= "</table></td>";
								return $str;
							}
						?>
						
						</tbody>
					</table>
					
					
					<div class="result page"><{$page}></div>
				</div>
	</div>
	
   
	
  </div>
  <div class="copy_layout">
      <p>
	  </p>
  </div>
   </div>
   
    
</body>

</html>
